//初始化模块
window.initialize = (function (_initialize) {
    var initialize = _initialize || [];
    initialize.push(function () {
        $(this).find('a[target],form[target]').filter(function () {
            return $(this).attr('target').indexOf("_") != 0;
        }).urlAjax();
    });
    initialize.push(function () {
        if (!$.fn.dropdownHover)return;
        $(this).find('[data-hover="dropdown"]').dropdownHover();
    });
    initialize.push(function () {
        $(this).find('[data-toggle="popover"]').popover({html: true});
    });
    initialize.push(function () {
        $(this).find('select:not(.not_init)').filter(function () {
            if (typeof $(this).data('minimum-results-for-search') == 'undefined') {
                $(this).data('minimum-results-for-search', "Infinity");
            }
            return true;
        }).select2();
    });
    initialize.push(function () {
        var target = $(this).findSelf('.validate').find('input,select,textarea').not("[type=submit],[type=file],[data-no-validate]").filter(function () {
            return !$(this).data('validate')
        });
        target.data('validate', target.jqBootstrapValidation(
            {
                sniffHtml: false,
                autoAdd: {helpBlocks: true},
                submitError: function ($form, event, errors) {
                    for (var key in errors) {
                        $('html').getNiceScroll(0).scrollTop($form.find('[name=' + key + ']').offset().top - $('.header').height() - 20);
                        return;
                    }
                },
                submitSuccess: function ($form, event) {
                    var result = $form.triggerHandler('validateSuccess');
                    if (result == false) {
                        return stopEvent(event);
                    }
                }
            }
        ));
    });
    initialize.push(function () {
        $('.fdatepicker', this).filter(function () {
            return !$(this).data('_fdatepicker');
        }).data('_fdatepicker', true).each(function () {
            //format:'yyyy-mm-dd hh:ii' ,pickTime: true
            $(this).fdatepicker($(this).data());
        })
    });
    initialize.push(function () {
        $(this).find('.nav-tabs a').click(function (e) {
            $(this).tab('show');
            return stopEvent(e);
        });
    })
    $.fn.initialize = function () {
        var zhis = this;
        $.each(initialize, function () {
            this.apply(zhis);
        });
        return $(this);
    };
})(window.initialize);
$(function () {
    $(document).initialize();
});